<?php
/**
 * Created by PhpStorm.
 * User: yuanjie
 * Date: 16/3/4
 * Time: 下午2:12
 * 上门车门店
 */
class OdsShopController extends BaseController{
    /*
     * 获取门店技师列表
     * */
    public function get_engineer_list(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                'shop_id' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("ods_error.args_miss_error_12001");
                break;
            }

            //传入参数
            $token = Input::get('token');
            $shop_id = Input::get('shop_id');

            //验证token
            $car_info = CarTokens::where('token',$token)->select(array('car_id'))->first();
            if(!is_null($car_info)){
                $engineers = MaintenanceEngineers::where('type','shop')
                    ->where('type_id',$shop_id)
                    ->select(array('id','name','title'))
                    ->get()
                    ->toArray();
            }else{
                Log::error("error", array("system" => "ods" ,"event" => "logout", 'input' =>Input::all()));
                $response = Lang::get("ods_error.token_check_error_12005");
                break;
            }

            //组织返回
            $response = array(
                'code' => 0,
                'msg' => 'ok',
                'result' => array(
                    'count' => count($engineers),
                    'engineers' => $engineers
                )
            );
        } while (false);
        Log::info("info", array("system" => "ods" ,"event" => "login", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
}